// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import 'element-ui/lib/theme-chalk/index.css'
import 'admin-lte/dist/css/adminlte.min.css'
import 'admin-lte/dist/css/skins/_all-skins.min.css'
import 'font-awesome/css/font-awesome.min.css'
import 'bootstrap/dist/css/bootstrap.min.css'
import './assets/animate.min.css'
import './assets/sys.css'

import './js/config.js'
import $ from 'jquery'
import 'bootstrap/dist/js/bootstrap.min.js'
import 'admin-lte'
import ElementUI from 'element-ui'
import echarts from 'echarts'

import axios from './js/httpRequestTool.js'
import fun from './js/function.js'
import store from "./vuex/store.js"

import App from './App'
import share from './share'
import router from './router'

import Vue from 'vue'
Vue.use(ElementUI);
Vue.prototype.$http = axios;
Vue.prototype.$echarts = echarts;
Vue.prototype.$store = store;
Vue.prototype.$fun = fun;
Vue.config.productionTip = false;

if(location.hash.search(/#\/share/i) >=0){
    // 查看分享
    new Vue({
    el: '#app',
    components: { share },
    template: '<share/>'
  });
} else {
  // 发起网络请求时检测并设置登录状态
  axios.interceptors.request.use(function (request) {
    if (request.url === 'checkIsLogin' || request.url === 'login' || request.url === 'logout') {
      return request;
    }
    else {
      store.dispatch('checkLoginState');
    }
    return request;
  });

  /*
  router.beforeEach(
    (to, from, next) => {
      // 路由发生改变时重新检测并设置登录状态
      // store.dispatch('checkLoginState');
      next();
    }
  );
  */

  // 打开或刷新时检测并设置登录状态
  store.dispatch('checkLoginState');

  new Vue({
    el: '#app',
    router,
    components: { App },
    template: '<App/>'
  });
}